package com.chatroomdemo.service;

import com.chatroomdemo.mapper.MessageMapper;
import com.chatroomdemo.model.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class MessageService {

    @Autowired
    private MessageMapper messageMapper;
    public List<Message> getMessageRecordBySessionId(Integer sessionId) {
        //对查询结果逆序操作，使消息按照时间顺序升序排列
        List<Message> messages = messageMapper.getMessageRecordBySessionId(sessionId);
        Collections.reverse(messages);
        return messages;
    }
}
